package com.zsrt.devbase.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zsrt.devbase.common.annotation.DataSource;
import com.zsrt.devbase.common.annotation.Paging;
import com.zsrt.devbase.common.utils.ConstantDefine;
import com.zsrt.devbase.common.utils.StringUtil;
import com.zsrt.devbase.dao.AccountDAO;
import com.zsrt.devbase.dto.AccountDTO;
import com.zsrt.devbase.service.AccountService;
@Service("accountService")
public class AccountServiceImpl extends BaseService<AccountDTO> implements AccountService{

	@Autowired
	private AccountDAO accountDAO;
	
	@Override
	public Map<String, Object> check(AccountDTO entity) {
		// TODO Auto-generated method stub
		return null;
	}

	@Paging
	@Override
	public Map<String, Object> selectAccount(AccountDTO account) {
		Map<String, Object> result = new HashMap<>();
		List<AccountDTO> list = accountDAO.select(account);
		result.put(ConstantDefine.ROWS, list);
		return result;
	}

	
	@Override
	@DataSource(name=DataSource.slave1)
	public Map<String, Object> selectAccount1(AccountDTO account) {
		Map<String, Object> result = new HashMap<>();
		List<AccountDTO> list = accountDAO.select(account);
		result.put(ConstantDefine.ROWS, list);
		return result;
	}

	@Override
	public List<AccountDTO> selectByTest(AccountDTO accountDTO) {
		List<AccountDTO> selectByTest = accountDAO.selectByTest(accountDTO);
		return selectByTest;
	}

	@Override
	public List<String> getRoleListByAccount(AccountDTO account) {
		List<String> roleList = null;
		if (null != account) {
			if (!StringUtil.isEmpty(account.getAccountCode())) {
				roleList = accountDAO.getRoleListByAccountCode(account.getAccountCode());
			}else if (!StringUtil.isEmpty(account.getEmail()) || StringUtil.isEmpty(account.getPhone())) {
				roleList = accountDAO.getRoleListByAccount(account);
			}else {
				return null;
						
			}
		}
		return roleList;
	}

}
